package com.qf.shixi.controller;

import com.qf.shixi.entity.Subject;
import com.qf.shixi.result.ResponseData;
import com.qf.shixi.service.SubjectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author
 * @since 2021-10-12 10:03:31
 */
@RestController
@RequestMapping("subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "通过项目类型查找对应的项目")
    @ApiImplicitParam(name="type",value = "项目类型",dataType = "string")
    @GetMapping("/api/query/{type}")
    public ResponseData queryByCondition(@PathVariable String type){
        List<Subject> subjects = subjectService.queryByType(type);
        if(subjects.size() == 0){
            return new ResponseData("1002","无数据");
        }
        return new ResponseData(subjects);
    }

    @ApiOperation(value = "通过id查找对应的项目")
    @ApiImplicitParam(name="id",value = "项目id",required = true)
    @GetMapping("/api/query/one/{id}")
    public ResponseData queryById(@PathVariable Integer id){
        Subject subject = subjectService.queryById(id);
        if(subject == null){
            return new ResponseData("1002","无数据");
        }
        return new ResponseData(subject);
    }

    @ApiOperation(value = "查找所有的项目名称")
    @GetMapping("/suname")
    public ResponseData querySuName() {
        List<String> sunames= subjectService.querySuName();
        return new ResponseData(sunames);
    }






}

